package com.fram.controller.api.android;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fram.bean.admin.android.withdrawal.request.WithdrawalAndroidRequest;
import com.fram.bean.api.android.wallet.request.WithdrawalAddRequest;
import com.fram.bean.sys.PageBean;
import com.fram.bean.sys.ResponseMsg;
import com.fram.common.canstant.ErrCode;
import com.fram.common.exception.ProException;
import com.fram.common.util.PublicMethod;
import com.fram.common.util.apiversion.ApiVersion;
import com.fram.common.util.base.BaseController;
import com.fram.entity.UserTransactionFlow;
import com.fram.service.api.v1.android.WithdrawalAndroidService;

@RestController
@RequestMapping("/api/{version}/app/manage/withdrawal")
public class WithdrawalAndroidController extends BaseController{
	
	private static Logger LOG = LoggerFactory.getLogger(WithdrawalAndroidController.class);
	
	@Autowired
	private WithdrawalAndroidService withdrawalAndroidService;
	// 
	@ApiVersion(1.0)
	@RequestMapping("add")
	private ResponseMsg add(@RequestBody WithdrawalAddRequest request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			request.setUserId(getApiUserId());
			withdrawalAndroidService.add(request);
		} catch (ProException e) {
			LOG.error("-提现错误-->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("--提现异常--->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	
	@ApiVersion(1.0)
	@RequestMapping("list")
	private ResponseMsg list(@RequestBody PageBean<WithdrawalAndroidRequest> request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			request.getParam().setUserId(getApiUserId());
			msg.setData(withdrawalAndroidService.list(request));
		} catch (ProException e) {
			LOG.error("-提现列表错误-->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("--提现列表异常--->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	
	@ApiVersion(1.0)
	@RequestMapping("money/detail/list")
	private ResponseMsg AmountDetail(@RequestBody PageBean<UserTransactionFlow> request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			request.getParam().setUserId(getApiUserId());
			msg.setData(withdrawalAndroidService.moneyDetailList(request));
		} catch (ProException e) {
			LOG.error("-金额明细列表错误-->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("--金额明细列表异常--->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
}
